{
 "cells":[
  {
   "cell_type":"code",
   "source":[
    "import numpy as np"
   ],
   "execution_count":1,
   "outputs":[
    
   ],
   "metadata":{
    "datalore":{
     "type":"CODE",
     "hide_input_from_viewers":false,
     "hide_output_from_viewers":false
    }
   }
  },
  {
   "cell_type":"code",
   "source":[
    "def Gauss_CPE(A,b):\n",
    "    n=len(b);index=1;x=np.zeros(n)\n",
    "    for k in range(n):\n",
    "        a_max=0\n",
    "        for i in range(k,n):\n",
    "            if abs(A[i][k])>a_max:\n",
    "                a_max = abs(A[i][k])\n",
    "                r=i\n",
    "        if a_max<0.00000001:\n",
    "            index=0\n",
    "            return\n",
    "        if r>k:\n",
    "            for j in range(k,n):\n",
    "                z=A[k][j];A[k][j]=A[r][j];A[r][j]=z\n",
    "            z=b[k];b[k]=b[r];b[r]=z;\n",
    "        for i in range(k+1,n):\n",
    "            m=A[i][k]\/A[k][k]\n",
    "            for j in range(k+1,n):\n",
    "                A[i][j]=A[i][j]-m*A[k][j]\n",
    "            b[i]=b[i]-m*b[k]\n",
    "    if abs(A[n-1][n-1])<0.0000001:\n",
    "        index=0\n",
    "        return\n",
    "    for k in range(n-1,0-1,-1):\n",
    "        for j in range(k+1,n):\n",
    "            b[k]=b[k]-A[k][j]*x[j]\n",
    "        x[k]=b[k]\/A[k][k]\n",
    "    return index, x\n",
    "A=[[1,2,3],[4,5,6],[7,8,0]]\n",
    "b=[2,3,1]\n",
    "print(Gauss_CPE(A,b))"
   ],
   "execution_count":2,
   "outputs":[
    {
     "name":"stdout",
     "text":[
      "(1, array([-1.        ,  1.        ,  0.33333333]))\n"
     ],
     "output_type":"stream"
    }
   ],
   "metadata":{
    "datalore":{
     "type":"CODE",
     "hide_input_from_viewers":false,
     "hide_output_from_viewers":false
    }
   }
  }
 ],
 "metadata":{
  "datalore":{
   "version":1,
   "computation_mode":"JUPYTER",
   "package_manager":"pip",
   "base_environment":"default",
   "packages":[
    
   ]
  }
 },
 "nbformat":4,
 "nbformat_minor":4
}